package com.xyazm.wms.api;

import com.xyazm.common.core.JsonResult;
import com.xyazm.common.utils.ParamCheckUtil;
import com.xyazm.wms.domain.param.PickGoodsParam;
import com.xyazm.wms.exception.WmsBizException;
import com.xyazm.wms.service.IWmsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 仓储服务对外暴露的接口实现类
 * @author xuyou
 * 2022/7/31 0031 21:53
*/
@Slf4j
@DubboService(version = "1.0.0",interfaceClass = IWmsApi.class,retries = 0)
public class WmsApi implements IWmsApi {

    @Autowired
    private IWmsService wmsService;

    @Override
    public JsonResult<Void> pickGoods(PickGoodsParam param) {
        try {
            ParamCheckUtil.checkObjectNonNull(param);
            wmsService.pickGoods(param);
            return JsonResult.buildSuccess();
        } catch (WmsBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    @Override
    public JsonResult<Void> cancelPickGoods(String orderId) {
        try {
            ParamCheckUtil.checkObjectNonNull(orderId);
            wmsService.cancelPickGoods(orderId);
            return JsonResult.buildSuccess();
        } catch (WmsBizException e) {
            log.error("biz error", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch(Exception e) {
            log.error("system error", e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
